define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	$scope.form.fk_role = params.fk_role;
	if($scope.form.fk_unit == null) {
		$scope.form.fk_unit = "self";
	}
	//查询所有单位
	httpService.post(app.urls.unit_selectSchoolAndAttach,$scope.form,function(data){
		if("0000" === data.code){
			$scope.unitList = data.data;
			$scope.findgrade();
			$scope.find();
			$scope.form.fk_unit = null;
		}else{
			alert(data.msg);
		}
	});
	
	$scope.findgrade = function(){
		httpService.post(app.urls.grade_selectCenterGrade,$scope.form,function(data){
			if("0000" === data.code){
				$scope.gradeList = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	
	$scope.findclass = function(){
		httpService.post(app.urls.class_selectByGradeAndUnit,$scope.form,function(data){
			if("0000" === data.code){
				$scope.classList = data.data;
			}else{
				alert(data.msg);
			}
		});
	}

	//查询用户数据
	$scope.find = function(){
		httpService.postpage(app.urls.student_selectNotExitRole,$scope.form,function(data){		
			if("0000" === data.code){
    			$scope.rows = data.data;
    		}else{
    			alert(data.msg);
    		}
		});
	}
	//按钮点击事件-条件查询
	$scope.select = function(){
    	$scope.page.current = 1;
    	$scope.find();
    }
	$scope.saveForm = function(){
		var values = [];
		$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
			values.push($(this).val());
		});
		if(values.length < 1){
			eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
		}else{
		$scope.form.users = JSON.stringify(values);
			httpService.post(app.urls.role_insertUserRole,$scope.form,function(data){
				if("0000" === data.code){
					var data = {id:params.fk_role,type:params.type,fk_group:params.fk_group};
					eventBusService.publish("content.page.reload",data);
					eventBusService.publish("modal.page.close",{});
	    		}else{
	    			alert(data.msg);
	    		}
			});
		}
	}
	
}}});